#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);  //这里的this是指画的对象
    //绘制直线
    //painter.drawLine(QPoint(20,20),QPoint(200,50));
    //painter.drawLine(20,20,500,300);
    //绘制矩形
    //painter.drawRect(10,10,400,300);
    //绘制圆形
    //painter.drawEllipse(QPoint(300,200),50,50);
    //绘制文字
    //设置字体
    QFont font("华文行楷",24);
    painter.setFont(font);
    //设置画笔颜色
    painter.setPen(Qt::red);
    //开始绘制
    painter.drawText(QPoint(200,300),"天行健，君子以自强不息");
}

